package com.ibeeking.found.cop.b.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.cop.b.rest.service.IFriendsTagsGroupService;
import com.ibeeking.found.cop.b.rest.service.IFriendsTagsService;
import com.ibeeking.found.cop.service.common.enums.MqSyncOperatorTypeEnum;
import com.ibeeking.found.cop.service.common.param.FriendsTagsBatchParam;
import com.ibeeking.found.cop.service.common.param.FriendsTagsGroupParam;
import com.ibeeking.found.cop.service.common.param.FriendsTagsParam;
import com.ibeeking.found.cop.service.common.query.FriendsTagsGroupPageQuery;
import com.ibeeking.found.cop.service.common.query.FriendsTagsGroupQuery;
import com.ibeeking.found.cop.service.common.query.FriendsTagsPageQuery;
import com.ibeeking.found.cop.service.common.query.FriendsTagsQuery;
import com.ibeeking.found.cop.service.common.vo.FriendsTagsGroupVO;
import com.ibeeking.found.cop.service.common.vo.FriendsTagsVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName FriendsTagsController
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/b/friendsTags/v1")
public class FriendsTagsController {

    @Resource
    private IFriendsTagsGroupService friendsTagsGroupServiceImpl;

    @Resource
    private IFriendsTagsService friendsTagsServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询客户标签列表")
    @PostMapping(value = "/list")
    public List<FriendsTagsGroupVO> list(@RequestBody FriendsTagsGroupQuery query) {
        return friendsTagsGroupServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询客户标签分页列表")
    @PostMapping(value = "/pageList")
    public Page<FriendsTagsGroupVO> pageList(@RequestBody FriendsTagsGroupPageQuery pageQuery) {
        return friendsTagsGroupServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "客户批量设置标签")
    @PostMapping(value = "/changeTagsBatch")
    public Boolean changeTagsBatch(@RequestBody @Validated FriendsTagsBatchParam param, @LoginUser CurrentUser currentUser) {
        return friendsTagsServiceImpl.changeTagsBatch(param, currentUser);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "添加客户标签")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) FriendsTagsGroupParam param) {
        return friendsTagsGroupServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改客户标签")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) FriendsTagsGroupParam param) {
        return friendsTagsGroupServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改是否启用")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return friendsTagsGroupServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看客户标签详情")
    @GetMapping(value = "/view/{id}")
    public FriendsTagsGroupVO view(@PathVariable("id") Long id) {
        return friendsTagsGroupServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除客户标签")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return friendsTagsGroupServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步客户标签")
    @PostMapping(value = "/syncFriendsTagsList")
    public Integer syncFriendsTagsList() {
        return friendsTagsServiceImpl.syncFriendsTagsFromWx();
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "同步客户标签到企微")
    @PostMapping(value = "/syncFriendsTagsToWxcp/{id}")
    public Integer syncFriendsTagsToWxcp(@PathVariable("id") Long id) {
        return friendsTagsGroupServiceImpl.sendInstructionToMq(id, MqSyncOperatorTypeEnum.COP_SYNC_FRIENDS_TAGS_EDIT.getCode());
    }

}
